package fr.utt.lo02.CrazyEights.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.*;

import fr.utt.lo02.CrazyEights.model.piles.DiscardPile;


/**
 * Represents the panel of the discardPile
 * @author Jeremy
 *
 */
public class DiscardPilePanel extends JPanel implements Observer{
	private static final long serialVersionUID = 1L;
	private DiscardPile discardPile;
	private ImageLabel imageLabel;
	private JLabel suitToPlay;
	
	/**
	 * Create the panel
	 * @param dp the discardPile represented by the panel
	 */
	public DiscardPilePanel(DiscardPile dp){
		discardPile = dp;
		dp.addObserver(this);
		this.setLayout(new GridBagLayout());
		suitToPlay = new JLabel("Actual suit: "+discardPile.getGameSuit());
		suitToPlay.setForeground(Color.white);
		imageLabel = new ImageLabel(discardPile.getCardOnTop());
		this.imageLabel.setPreferredSize(new Dimension(MainWindow.cardWidth, MainWindow.cardHeight));
		GridBagConstraints c = new GridBagConstraints();
		c.gridy = 0;
		this.add(imageLabel,c);
		c.gridy = 1;
		this.add(suitToPlay,c);
	}
	
	public void update(Observable o, Object arg){
		imageLabel.setImagePath(discardPile.getCardOnTop());
		suitToPlay.setText("Actual suit: "+discardPile.getGameSuit());
	}
}